package com.yegs.quartz.service.impl;

import com.yegs.quartz.mysqlEntity.User;
import com.yegs.quartz.mysqlRepository.UserRepository;
import com.yegs.quartz.service.UserService;
import com.yegs.quartz.sqlServerEntity.Student;
import com.yegs.quartz.sqlServerRepository.StudentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("userService")
public class UserServiceImpl implements UserService {

    @Autowired
    private UserRepository userRepository;

    @Autowired
    private StudentRepository studentRepository;


    @Override
    public List<User> findAll() {
        return userRepository.findAll();
    }

    @Override
    public List<Student> findAllStudent() {
        return studentRepository.findAll();
    }

    @Override
    public void userToStudent() {
        Student stu = studentRepository.getOne(1L);
        User user = userRepository.getOne(1L);
        Student s = new Student();
        s.setName(user.getName());
        User u = new User();
        u.setName(stu.getName());
        studentRepository.save(s);
        userRepository.save(u);
    }

}
